<%
  # encoding: utf-8
  #
  # Redmine plugin for Document Management System "Features"
  #
  # Copyright © 2011-21 Karel Pičman <karel.picman@kontron.com>
  #
  # This program is free software; you can redistribute it and/or
  # modify it under the terms of the GNU General Public License
  # as published by the Free Software Foundation; either version 2
  # of the License, or (at your option) any later version.
  #
  # This program is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with this program; if not, write to the Free Software
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
%>

<li>
  <%= context_menu_link l(:button_edit), dmsf_file_path(id: dmsf_file), class: 'icon icon-edit',
                        disabled: !allowed || (locked && !unlockable) %>
</li>
<% unless dmsf_link %>
  <li>
    <%= link_to "#{l(:button_copy)}/#{l(:button_move)}", copy_file_path(id: dmsf_file),
                title: l(:title_copy), class: 'icon icon-copy'  %>
  </li>
  <li>
    <%= link_to l(:label_link_to),
              new_dmsf_link_path(project_id: dmsf_file.project.id, dmsf_folder_id: dmsf_file.dmsf_folder&.id,
                                 dmsf_file_id: dmsf_file.id, type: 'link_to'),
              title: l(:title_create_link), class: 'icon dmsf-icon-link' %>
  </li>
<% end %>
<li>
    <% if locked %>
      <%= context_menu_link l(:button_unlock), unlock_dmsf_files_path(id: dmsf_file), class: 'icon icon-unlock',
                            title: l(:title_locked_by_user, user: dmsf_file.locked_by),
                            disabled: !unlockable %>
    <% else %>
      <%= context_menu_link l(:button_lock), lock_dmsf_files_path(id: dmsf_file), class: 'icon icon-lock',
                            disabled: !allowed %>
    <% end %>
</li>
<li>
  <% if dmsf_file.notification %>
      <%= context_menu_link l(:label_notifications_off), notify_deactivate_dmsf_files_path(id: dmsf_file),
                            class: 'icon icon-email', disabled: !allowed || locked %>
  <% else %>
      <%= context_menu_link l(:label_notifications_on), notify_activate_dmsf_files_path(id: dmsf_file),
                            class: 'icon icon-email-add', disabled: !allowed || locked %>
  <% end %>
</li>
<li>
    <%= render partial: 'approval_workflow', locals: { dmsf_file: dmsf_file, project: project, locked: locked } %>
</li>
<li>
<%= context_menu_link l(:button_download), view_dmsf_file_path(dmsf_file, disposition: 'attachment'),
                      class: 'icon icon-download', disabled: false %>
</li>
<li>
<%= context_menu_link l(:field_mail), entries_operations_dmsf_path(id: project, folder_id: folder,
   ids: params[:ids], email_entries: true), method: :post, class: 'icon icon-email',
   disabled: !email_allowed %>
</li>
<% if Setting.plugin_redmine_dmsf['dmsf_webdav'].present? %>
  <li>
    <% if dmsf_file.last_revision && dmsf_file.last_revision.protocol %>
      <% url = "#{dmsf_file.last_revision.protocol}:ofe|u|#{Setting.protocol.strip}://#{Setting.host_name.strip}/dmsf/webdav/#{Addressable::URI.escape(RedmineDmsf::Webdav::ProjectResource.create_project_name(dmsf_file.project))}/" %>
      <% if dmsf_file.dmsf_folder %>
        <% url << "#{dmsf_file.dmsf_folder.dmsf_path_str}/" %>
      <% end %>
      <% url << dmsf_file.name %>
    <% end %>
    <%= context_menu_link l(:button_edit_content), url, class: "icon icon-file #{DmsfHelper.filetype_css(dmsf_file.name)}",
          disabled: url.blank? || (locked && (!unlockable)) ||
            (Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] != 'WEBDAV_READ_WRITE') %>
  </li>
<% end %>
<li>
  <%= context_menu_link l(:button_delete),
        dmsf_link ? dmsf_link_path(id: dmsf_link, folder_id: folder) : dmsf_file_path(id: dmsf_file, folder_id: folder),
        method: :delete, class: 'icon icon-del', data: { confirm: l(:text_are_you_sure) }, id: 'dmsf-cm-delete',
        disabled: !allowed || (locked && !dmsf_link) %>
</li>
